package windowFactoryPackage;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class PreviousDownloadsWindow extends WindowGenerator {
	//Declare window components
	static ArrayList<JLabel> downloadNumList = new ArrayList<JLabel>();
	static ArrayList<JLabel> downloadProgramList = new ArrayList<JLabel>();
	static ArrayList<JLabel> downloadDateList = new ArrayList<JLabel>();
	private JScrollPane jspDownloads;
	private JPanel mainPanel, numArrayPanel, programArrayPanel, dateArrayPanel;
	
	public PreviousDownloadsWindow(){
		//Set layout for parent JFrame
		setLayout(new BorderLayout());
		
		//Instantiate mainPanel
		mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());
		
		//Instantiate numArrayPanel, populate Array, add array to panel
		
		for(int i = 0; i<downloadProgramList.size(); i++){
			downloadNumList.add(new JLabel("Download " + (i + 1) + ": "));
			downloadNumList.get(i).setBorder(BorderFactory.createEtchedBorder());
		}
		
		numArrayPanel = new JPanel();
		if(downloadNumList.size() < 10){
			numArrayPanel.setLayout(new GridLayout(10, 0, 10, 10));
		}else{
			numArrayPanel.setLayout(new GridLayout(downloadNumList.size(), 0, 10, 10));
		}
		
		for(int i = 0; i<downloadNumList.size(); i++){
			numArrayPanel.add(downloadNumList.get(i));
		}
		
		mainPanel.add(numArrayPanel, BorderLayout.WEST);
		
		//Instantiate programArrayPanel, populateArray, add array to panel
		
		for(int i = 0; i<downloadProgramList.size(); i++){
			downloadProgramList.get(i).setBorder(BorderFactory.createEtchedBorder());
		}
		
		programArrayPanel = new JPanel();
		if(downloadNumList.size() < 10){
			programArrayPanel.setLayout(new GridLayout(10, 0, 10, 10));
		}else{
			programArrayPanel.setLayout(new GridLayout(downloadProgramList.size(), 0, 10, 10));
		}
		
		for(int i = 0; i<downloadNumList.size(); i++){
			programArrayPanel.add(downloadProgramList.get(i));
		}
		
		mainPanel.add(programArrayPanel, BorderLayout.CENTER);
		
		//Instantiate dateArrayPanel, populate Array, add array to Panel
		for(int i = 0; i<downloadNumList.size(); i++){
			downloadDateList.get(i).setBorder(BorderFactory.createEtchedBorder());
		}
		
		dateArrayPanel = new JPanel();
		if(downloadNumList.size() < 10){
			dateArrayPanel.setLayout(new GridLayout(10, 0, 10, 10));
		}else{
			dateArrayPanel.setLayout(new GridLayout(downloadDateList.size(), 0, 10, 10));
		}
		
		for(int i = 0; i<downloadDateList.size(); i++){
			dateArrayPanel.add(downloadDateList.get(i));
		}
		
		mainPanel.add(dateArrayPanel, BorderLayout.EAST);
		
		//Instantiate JScrollPane and add mainPanel
		jspDownloads = new JScrollPane(mainPanel);
		jspDownloads.getVerticalScrollBar().setUnitIncrement(16);
		
		//Add JScrollPane to parent JFrame
		add(jspDownloads, BorderLayout.CENTER);
	}
}
